package KH;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class JAXB {
	public static void main(String[] args) {
		 
		  Customer customer = new Customer();
		  customer.setId(111);
		  customer.setName("Nguyen Ha Giang");
		  customer.setAge(21);
	 
		  try {
	 
			File file = new File("E:/file.xml");
			JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
			Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
	 
			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	 
			jaxbMarshaller.marshal(customer, file);
			jaxbMarshaller.marshal(customer, System.out);
	 
		      } catch (JAXBException e) {
			e.printStackTrace();
		      }
	 
		}

}
